﻿@model IEnumerable<Eieboom.Models.blog_article> 
@using res = Sob.Resource.Views.Admin.Admin;
@{Eieboom.General.GeneralConfigInfo ci = ViewBag.CI as Eieboom.General.GeneralConfigInfo;}
@section MenuInfo{
<ul> 
    <li>@Html.ActionLink("-" + res.ManagementHome + " -", "Index", "Admin")</li>
    <li class="selected">
        <span class="selected-arrow">&nbsp;</span>
        <a href="###">- @res.ContentManagement -</a>
        <ul>
            <li id="t1">@Html.ActionLink(res.Article, "AdminArticle", "Admin", new { tid = 1 }, null)</li>
            <li id="t2">@Html.ActionLink(res.SinglePage, "AdminArticle", "Admin", new { tid = 2 }, null)</li>
            <li id="t5" class="v10">@Html.ActionLink(res.Posts, "AdminArticle", "Admin", new { tid = 5 }, null)</li>
            <li id="t4">@Html.ActionLink(res.Album, "AdminArticle", "Admin", new { tid = 4 }, null)</li>
            <li id="t6">@Html.ActionLink(res.Message, "AdminArticle", "Admin", new { tid = 6 }, null)</li>
            <li id="l1">@Html.ActionLink(res.Comment, "AdminArticle", "Admin", new { layer = 1 }, null)</li>
            <li id="t7">@Html.ActionLink(res.CustomArea, "AdminArticle", "Admin", new { tid = 7 }, null)</li>
            <li id="t8">@Html.ActionLink(res.CustomGlobalArea, "AdminArticle", "Admin", new { tid = 8 }, null)</li>
        </ul>
    </li>
    <li>@Html.ActionLink("-" + res.Configuration + " -", "AdminBaseConfig", "Admin")</li>
    <li>@Html.ActionLink("-" + res.UserManagement + " -", "AdminUserList", "Admin")</li>
</ul>
}

<div id="mainContent">
        <div id="leftBox">
          <div id="pagePath">
          <span class="location"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;
            @if (ViewBag.LayerId == 0 && (ViewBag.TypeId == 1 || ViewBag.TypeId == 2 || ViewBag.TypeId == 4 || ViewBag.TypeId == 7 || ViewBag.TypeId == 8))
            {
                if (ViewBag.TypeId != 7 && ViewBag.TypeId != 8)
                {
                <span class="red">@res.Filter：</span><span class="sortbtn"><a href="###" p="all" @(string.IsNullOrEmpty(ViewBag.Sort) ? "class=current" : "")>@res.All</a> <a href="###" p="normal" >@res.Normal</a> <a href="###" p="status" >@res.Draft</a> <a href="###" p="istop" >@res.Top</a> <a href="###" p="iscommend" >@res.Recommend</a> </span>
                @:| 
                <span class="red">@res.Sort: </span><span class="orderbtn"><a href="###" p="desc" @(string.IsNullOrEmpty(ViewBag.Order) ? "class=current" : "")>@res.Descending</a> <a href="###" p="asc">@res.Ascending</a> </span>
                }
                <div class="add">
                @Html.ActionLink(res.Add, "AdminAdd", "Admin", new { tid = ViewBag.TypeId, cid = ViewBag.Cid }, null)
                 <p>@Html.DropDownList("CateId")</p>
                </div>
            }
          </div>

          <div class="contentBox">
            <div class="contentBoxTop">
              <h3>@res.ContentList</h3>
            </div>
            <div class="innerContent">
              <form action="" method="post" name="form2" id="form2">
                <table class="sTable">
				<thead>
                  <tr>
                    <th></th>
                    <th><strong>ID</strong></th>
                    <th><strong></strong></th>
                    <th><strong>@res.Date</strong></th>
                    <th><strong>@res.Operating</strong></th>
                    </tr>
                </thead>
                  <tbody>

    @if ((Model as IEnumerable<Eieboom.Models.blog_article>).Count() > 0)
    {
        foreach (var item in Model)
        {
                  <tr class="oddRow" id="@item.id">
                    <td class="zeroCol">
                    <input type="checkbox" onfocus="this.blur()" value="@item.id" pid="@item.parentid" name="chkArticle"/>
                    </td>
                    <td class="firstCol"><a href="#">@item.id</a></td>
                    <td class="secondCol">
                        @{string newtitle = "";}
                        @if (item.layer != 0 || item.typeid == 6 || item.typeid == 7 || item.typeid == 8)
                        {
                            newtitle = item.content;
                            if (item.content.Length > 20)
                            { newtitle = item.content.Substring(0, 20) + "..."; }
                            if (string.IsNullOrWhiteSpace(newtitle))
                            { newtitle = @res.Title; }
                             <a href="###" title="@item.content">@newtitle</a>
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(item.title))
                            { newtitle = res.Title; }
                            else
                            { newtitle = item.title; }

                            string actionstr = "archive";
                            switch (item.typeid)
                            {
                                case 4:
                                    actionstr = "Album";
                                    break;
                                case 5:
                                    actionstr = "Thread";
                                    break;
                            }
                            <a href="/@actionstr/@item.id" title="@item.title" target="_blank">@newtitle</a>
                        }
                    </td>
                    <td  class="forthCol">@item.createdate.ToString("yyyy-MM-dd hh:mm")</td>
                    <td class="editItem"><ul>
                        @if (item.layer == 0 && item.typeid != 6)
                        {
                            <li class="iconEdit">@Html.ActionLink(res.Edit, "AdminEdit", "Admin", new { id = item.id }, null)</li>
                        }
                      <li class="iconDel"><a href="javascript:" onclick="Del(@item.id,@item.parentid)">@res.Delete</a></li>
                    </ul></td>
                    </tr>
        }
    }
                </tbody></table>
                <div class="pager"></div>
                <p><a class="deleteLink" href="javascript:" onclick="DelBatch()">@res.DeleteSelected</a></p>
              </form>
            </div><!--end of #box-3-->
          </div>

      </div><!-- end of #leftBox -->
              
  </div><!-- end of #content -->
@section Js{
    <script src="@Url.Content("~/Scripts/jquery.pager.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var pageNo = @ViewBag.PageNo;
        var pageCount = @ViewBag.PageCount;
        var typeid=@ViewBag.TypeId;
        var layerid=@ViewBag.LayerId;
        var cateid=@ViewBag.Cid;
        var sortpara="@ViewBag.Sort";
        var orderpara="@ViewBag.Order";
        var currentitem="@ViewBag.CurrentItem";

        $(document).ready(function () {
            if (pageCount == 0) { $(".pager").hide() }
            $(".pager").pager({ pagenumber: pageNo, pagecount: pageCount, buttonClickCallback: PageClick });

            $('#CateId').change(function(){ 
                var p1=$(this).children('option:selected').val();
                window.location.href="?tid=" + typeid +"&layer=" + layerid +"&cid=" + p1 +"&sort=" + sortpara +"&order=" + orderpara;
            });

            $('.sortbtn a').click(function(){ 
                var p=$(this).attr("p");
                window.location = "?tid=" + typeid+"&layer=" + layerid+"&cid=" + cateid+"&sort=" + p+"&order=" + orderpara;
            });

            $('.orderbtn a').click(function(){ 
                var p=$(this).attr("p");
                window.location = "?tid=" + typeid+"&layer="+layerid+"&cid=" + cateid+"&sort=" + sortpara+"&order=" + p;
            });

            $(".sortbtn a").each(function (index, domEle) {
                if($(this).attr("p")==sortpara)
                {
                    $(this).addClass("current");
                }
            });

            $(".orderbtn a").each(function (index, domEle) {
                if($(this).attr("p")==orderpara)
                {
                    $(this).addClass("current");
                }
            });

            $("#"+currentitem).addClass("selected");
            $(".location").html($("#"+currentitem+" a").html());
            
        });

        PageClick = function (no) {
            window.location = "?pageNo=" + no+"&tid=" + typeid+"&layer=" + layerid+"&cid=" + cateid+"&sort=" + sortpara+"&order=" + orderpara;
        }

        Del=function(id, parentid) {
            if (confirm("@(res.DeleteSelected_Tip)")) {

                $.post('/BlogAdmin/Admin/AdminDel', { id: id, parentid: parentid }, function (data) {
                    alert(data);
                    $('#' + id).fadeOut('fast', function () {
                        $(this).remove();
                    });
                });
            }
        }

        DelBatch=function()
        {
            if (confirm("@(res.Delete_Tip)")) {
                var str="";
                $("input[name='chkArticle']").each(function(){
                    if($(this).attr("checked"))
                    {
                        var itemid=$(this).val();
                        var itempid=$(this).attr("pid");
                        $.post('/BlogAdmin/Admin/AdminDel', { id: itemid, parentid:itempid }, function (data) {
                            $('#' + itemid).fadeOut('fast', function () {
                                $(this).remove();
                            });
                        });

                    }
                })
            }
        }
    </script>
}
